home *** CD-ROM | disk | FTP | other *** search
/ Aminet 45 / Aminet 45 (2001)(GTI - Schatztruhe)[!][Oct 2001].iso / Aminet / gfx / x11 / x3270_3_2_16.lha / amiga_src / about.c < prev    next >
C/C++ Source or Header  |  2008-12-03  |  11KB  |  418 lines

  1. /*
  2.  * Copyright 1993, 1994, 1995, 1999, 2000 by Paul Mattes.
  3.  *  Permission to use, copy, modify, and distribute this software and its
  4.  *  documentation for any purpose and without fee is hereby granted,
  5.  *  provided that the above copyright notice appear in all copies and that
  6.  *  both that copyright notice and this permission notice appear in
  7.  *  supporting documentation.
  8.  */
  9.  
  10. /*
  11.  *    about.c
  12.  *        Pop-up window with the current state of x3270.
  13.  */
  14.  
  15. #include "globals.h"
  16.  
  17. #if defined(X3270_MENUS) /*[*/
  18.  
  19. #include <X11/Shell.h>
  20. #include <X11/StringDefs.h>
  21. #include <X11/Xaw/Command.h>
  22. #include <X11/Xaw/Form.h>
  23. #include <X11/Xaw/Label.h>
  24. #include "appres.h"
  25. #include "objects.h"
  26. #include "resources.h"
  27.  
  28. #include "aboutc.h"
  29. #include "keymapc.h"
  30. #include "popupsc.h"
  31. #include "telnetc.h"
  32. #include "utilc.h"
  33.  
  34. static Widget about_shell = NULL;
  35. static Widget about_form;
  36. extern time_t ns_time;
  37. extern int ns_brcvd;
  38. extern int ns_rrcvd;
  39. extern int ns_bsent;
  40. extern int ns_rsent;
  41. extern int linemode;
  42. extern Pixmap icon;
  43.  
  44. /* Called when OK is pressed on the about popup */
  45. static void
  46. saw_about(Widget w unused, XtPointer client_data unused,
  47.     XtPointer call_data unused)
  48. {
  49.     XtPopdown(about_shell);
  50. }
  51.  
  52. /* Called when the about popup is popped down */
  53. static void
  54. destroy_about(Widget w unused, XtPointer client_data unused,
  55.     XtPointer call_data unused)
  56. {
  57.     XtDestroyWidget(about_shell);
  58.     about_shell = NULL;
  59. }
  60.  
  61. /* Return a time difference in English */
  62. static char *
  63. hms(time_t ts)
  64. {
  65.     time_t t, td;
  66.     long hr, mn, sc;
  67.     static char buf[128];
  68.  
  69.     (void) time(&t);
  70.  
  71.     td = t - ts;
  72.     hr = td / 3600;
  73.     mn = (td % 3600) / 60;
  74.     sc = td % 60;
  75.  
  76.     if (hr > 0)
  77.         (void) sprintf(buf, "%ld %s %ld %s %ld %s",
  78.             hr, (hr == 1) ?
  79.             get_message("hour") : get_message("hours"),
  80.             mn, (mn == 1) ?
  81.             get_message("minute") : get_message("minutes"),
  82.             sc, (sc == 1) ?
  83.             get_message("second") : get_message("seconds"));
  84.     else if (mn > 0)
  85.         (void) sprintf(buf, "%ld %s %ld %s",
  86.             mn, (mn == 1) ?
  87.             get_message("minute") : get_message("minutes"),
  88.             sc, (sc == 1) ?
  89.             get_message("second") : get_message("seconds"));
  90.     else
  91.         (void) sprintf(buf, "%ld %s",
  92.             sc, (sc == 1) ?
  93.             get_message("second") : get_message("seconds"));
  94.  
  95.     return buf;
  96. }
  97.  
  98. #define MAKE_SMALL(label, n) { \
  99.     w_prev = w; \
  100.     w = XtVaCreateManagedWidget( \
  101.         ObjSmallLabel, labelWidgetClass, about_form, \
  102.         XtNborderWidth, 0, \
  103.         XtNlabel, label, \
  104.         XtNfromVert, w, \
  105.         XtNleft, XtChainLeft, \
  106.         XtNvertDistance, (n), \
  107.         NULL); \
  108.     vd = n; \
  109.     }
  110.  
  111. #define MAKE_LABEL(label, n) { \
  112.     w_prev = w; \
  113.     w = XtVaCreateManagedWidget( \
  114.         ObjNameLabel, labelWidgetClass, about_form, \
  115.         XtNborderWidth, 0, \
  116.         XtNlabel, label, \
  117.         XtNfromVert, w, \
  118.         XtNfromHoriz, left_anchor, \
  119.         XtNleft, XtChainLeft, \
  120.         XtNvertDistance, (n), \
  121.         NULL); \
  122.     vd = n; \
  123.     }
  124.  
  125. #define MAKE_VALUE(label) { \
  126.     v = XtVaCreateManagedWidget( \
  127.         ObjDataLabel, labelWidgetClass, about_form, \
  128.         XtNborderWidth, 0, \
  129.         XtNlabel, label, \
  130.         XtNfromVert, w_prev, \
  131.         XtNfromHoriz, w, \
  132.         XtNhorizDistance, 0, \
  133.         XtNvertDistance, vd, \
  134.         XtNleft, XtChainLeft, \
  135.         NULL); \
  136.     }
  137.  
  138. #define MAKE_LABEL2(label) { \
  139.     w = XtVaCreateManagedWidget( \
  140.         ObjNameLabel, labelWidgetClass, about_form, \
  141.         XtNborderWidth, 0, \
  142.         XtNlabel, label, \
  143.         XtNfromVert, w_prev, \
  144.         XtNfromHoriz, v, \
  145.         XtNhorizDistance, 0, \
  146.         XtNvertDistance, vd, \
  147.         XtNleft, XtChainLeft, \
  148.         NULL); \
  149.     }
  150.  
  151. /* Called when the "About x3270..." button is pressed */
  152. void
  153. popup_about(void)
  154. {
  155.     Widget w = NULL, w_prev = NULL;
  156.     Widget v = NULL;
  157.     Widget left_anchor = NULL;
  158.     int vd = 4;
  159.     char fbuf[1024];
  160.     const char *ftype;
  161.     const char *emode;
  162. #if defined(X3270_TN3270E) /*[*/
  163.     const char *eopts;
  164. #endif /*]*/
  165.     char *xbuf;
  166.  
  167.     /* Create the popup */
  168.  
  169.     about_shell = XtVaCreatePopupShell(
  170.         "aboutPopup", transientShellWidgetClass, toplevel,
  171.         NULL);
  172.     XtAddCallback(about_shell, XtNpopupCallback, place_popup,
  173.         (XtPointer) CenterP);
  174.     XtAddCallback(about_shell, XtNpopdownCallback, destroy_about,
  175.         NULL);
  176.  
  177.     /* Create a form in the popup */
  178.  
  179.     about_form = XtVaCreateManagedWidget(
  180.         ObjDialog, formWidgetClass, about_shell,
  181.         NULL);
  182.  
  183.     /* Pretty picture */
  184.  
  185.     left_anchor = XtVaCreateManagedWidget(
  186.         "icon", labelWidgetClass, about_form,
  187.         XtNborderWidth, 0,
  188.         XtNbitmap, icon,
  189.         XtNfromVert, w,
  190.         XtNleft, XtChainLeft,
  191.         NULL);
  192.  
  193.     /* Miscellany */
  194.  
  195.     MAKE_LABEL(build, 4);
  196.     MAKE_LABEL(get_message("processId"), 4);
  197.     (void) sprintf(fbuf, "%d", getpid());
  198.     MAKE_VALUE(fbuf);
  199.     MAKE_LABEL2(get_message("windowId"));
  200.     (void) sprintf(fbuf, "0x%lx", XtWindow(toplevel));
  201.     MAKE_VALUE(fbuf);
  202.  
  203.     /* Everything else at the left margin under the bitmap */
  204.     w = left_anchor;
  205.     left_anchor = NULL;
  206.  
  207.     MAKE_SMALL("Modifications Copyright \251 1993, 1994, 1995, 1996, 1997, 1999, 2000 by Paul Mattes.\n\
  208. Original X11 Port Copyright \251 1990 by Jeff Sparkes.\n\
  209. File transfer code Copyright \251 1995 by Dick Altenbern.\n\
  210. Includes IAC IP patch by Carey Evans, 1998.\n\
  211.  Permission to use, copy, modify, and distribute this software and its documentation\n\
  212.  for any purpose and without fee is hereby granted, provided that the above copyright\n\
  213.  notice appear in all copies and that both that copyright notice and this permission\n\
  214.  notice appear in supporting documentation.\n\
  215. \n\
  216. Copyright \251 1989 by Georgia Tech Research Corporation, Atlanta, GA 30332.\n\
  217.  All Rights Reserved.  GTRC hereby grants public use of this software.  Derivative\n\
  218.  works based on this software must incorporate this copyright notice.", 4);
  219.  
  220.     (void) sprintf(fbuf, "%s %s: %d %s x %d %s, %s, %s",
  221.         get_message("model"), model_name,
  222.         maxCOLS, get_message("columns"),
  223.         maxROWS, get_message("rows"),
  224.         appres.mono ? get_message("mono") :
  225.         (appres.m3279 ? get_message("fullColor") :
  226.             get_message("pseudoColor")),
  227.         (appres.extended && !std_ds_host) ? get_message("extendedDs") :
  228.         get_message("standardDs"));
  229.     MAKE_LABEL(fbuf, 4);
  230.  
  231.     MAKE_LABEL(get_message("terminalName"), 4);
  232.     MAKE_VALUE(termtype);
  233.     if (connected_lu != CN && connected_lu[0]) {
  234.         MAKE_LABEL2(get_message("luName"));
  235.         MAKE_VALUE(connected_lu);
  236.     }
  237.  
  238.     MAKE_LABEL(get_message("emulatorFont"), 4);
  239.     MAKE_VALUE(efontname);
  240.     if (*standard_font) {
  241.         if (*latin1_font)
  242.             ftype = get_message("fullFont");
  243.         else
  244.             ftype = get_message("asciiFont");
  245.     } else
  246.         ftype = get_message("cgFont");
  247.     xbuf = xs_buffer("  %s", ftype);
  248.     MAKE_LABEL(xbuf, 0);
  249.     XtFree(xbuf);
  250.  
  251.     if (appres.charset) {
  252.         MAKE_LABEL(get_message("characterSet"), 4);
  253.         MAKE_VALUE(appres.charset);
  254.     } else {
  255.         MAKE_LABEL(get_message("defaultCharacterSet"), 4);
  256.     }
  257.  
  258.     if (trans_list != (struct trans_list *)NULL ||
  259.         temp_keymaps != (struct trans_list *)NULL) {
  260.         struct trans_list *t;
  261.  
  262.         fbuf[0] = '\0';
  263.         for (t = trans_list; t; t = t->next) {
  264.             if (fbuf[0])
  265.                 (void) strcat(fbuf, ",");
  266.             (void) strcat(fbuf, t->name);
  267.         }
  268.         for (t = temp_keymaps; t; t = t->next) {
  269.             if (fbuf[0])
  270.                 (void) strcat(fbuf, " ");
  271.             (void) strcat(fbuf, "+");
  272.             (void) strcat(fbuf, t->name);
  273.         }
  274.         MAKE_LABEL(get_message("keyboardMap"), 4)
  275.         MAKE_VALUE(fbuf);
  276.     } else
  277.         MAKE_LABEL(get_message("defaultKeyboardMap"), 4);
  278.     if (appres.compose_map) {
  279.         MAKE_LABEL(get_message("composeMap"), 4);
  280.         MAKE_VALUE(appres.compose_map);
  281.     } else {
  282.         MAKE_LABEL(get_message("noComposeMap"), 4);
  283.     }
  284.  
  285.     if (appres.active_icon) {
  286.         MAKE_LABEL(get_message("activeIcon"), 4);
  287.         xbuf = xs_buffer("  %s", get_message("iconFont"));
  288.         MAKE_LABEL(xbuf, 0);
  289.         XtFree(xbuf);
  290.         MAKE_VALUE(appres.icon_font);
  291.         if (appres.label_icon) {
  292.             xbuf = xs_buffer("  %s", get_message("iconLabelFont"));
  293.             MAKE_LABEL(xbuf, 0);
  294.             XtFree(xbuf);
  295.             MAKE_VALUE(appres.icon_label_font);
  296.         }
  297.     } else
  298.         MAKE_LABEL(get_message("staticIcon"), 4);
  299.  
  300.     if (CONNECTED) {
  301.         MAKE_LABEL(get_message("connectedTo"), 4);
  302. #if defined(LOCAL_PROCESS) /*[*/
  303.         if (local_process && !strlen(current_host)) {
  304.             MAKE_VALUE("(shell)");
  305.         } else
  306. #endif /*]*/
  307.         {
  308.             MAKE_VALUE(current_host);
  309.         }
  310. #if defined(LOCAL_PROCESS) /*[*/
  311.         if (!local_process) {
  312. #endif /*]*/
  313.             (void) sprintf(fbuf, "  %s", get_message("port"));
  314.             MAKE_LABEL2(fbuf);
  315.             (void) sprintf(fbuf, "%d", current_port);
  316.             MAKE_VALUE(fbuf);
  317. #if defined(LOCAL_PROCESS) /*[*/
  318.         }
  319. #endif /*]*/
  320.         if (IN_E)
  321.             emode = "TN3270E ";
  322.         else
  323.             emode = "";
  324.         if (IN_ANSI) {
  325.             if (linemode)
  326.                 ftype = get_message("lineMode");
  327.             else
  328.                 ftype = get_message("charMode");
  329.             (void) sprintf(fbuf, "  %s%s, ", emode, ftype);
  330.         } else if (IN_SSCP) {
  331.             (void) sprintf(fbuf, "  %s%s, ", emode,
  332.                 get_message("sscpMode"));
  333.         } else if (IN_3270) {
  334.             (void) sprintf(fbuf, "  %s%s, ", emode,
  335.                 get_message("dsMode"));
  336.         } else
  337.             (void) strcpy(fbuf, "  ");
  338.         (void) strcat(fbuf, hms(ns_time));
  339.  
  340.         MAKE_LABEL(fbuf, 0);
  341.  
  342. #if defined(X3270_TN3270E) /*[*/
  343.         eopts = tn3270e_current_opts();
  344.         if (eopts != CN) {
  345.             (void) sprintf(fbuf, "  %s",
  346.                  get_message("tn3270eOpts"));
  347.             MAKE_LABEL(fbuf, 0);
  348.             MAKE_VALUE(eopts);
  349.         } else if (IN_E) {
  350.             (void) sprintf(fbuf, "  %s",
  351.                 get_message("tn3270eNoOpts"));
  352.             MAKE_LABEL(fbuf, 0);
  353.         }
  354. #endif /*]*/
  355.  
  356.         if (IN_3270)
  357.             (void) sprintf(fbuf, "%s %d %s, %d %s\n%s %d %s, %d %s",
  358.                 get_message("sent"),
  359.                 ns_bsent, (ns_bsent == 1) ?
  360.                 get_message("byte") : get_message("bytes"),
  361.                 ns_rsent, (ns_rsent == 1) ?
  362.                 get_message("record") : get_message("records"),
  363.                 get_message("Received"),
  364.                 ns_brcvd, (ns_brcvd == 1) ?
  365.                 get_message("byte") : get_message("bytes"),
  366.                 ns_rrcvd, (ns_rrcvd == 1) ?
  367.                 get_message("record") : get_message("records"));
  368.         else
  369.             (void) sprintf(fbuf, "%s %d %s, %s %d %s",
  370.                 get_message("sent"),
  371.                 ns_bsent, (ns_bsent == 1) ?
  372.                 get_message("byte") : get_message("bytes"),
  373.                 get_message("received"),
  374.                 ns_brcvd, (ns_brcvd == 1) ?
  375.                 get_message("byte") : get_message("bytes"));
  376.         MAKE_LABEL(fbuf, 4);
  377.  
  378.         if (IN_ANSI) {
  379.             struct ctl_char *c = net_linemode_chars();
  380.             int i;
  381.  
  382.             MAKE_LABEL(get_message("specialCharacters"), 4);
  383.             for (i = 0; c[i].name; i++) {
  384.                 if (!i || !(i % 4)) {
  385.                     (void) sprintf(fbuf, "  %s", c[i].name);
  386.                     MAKE_LABEL(fbuf, 0);
  387.                 } else {
  388.                     MAKE_LABEL2(c[i].name);
  389.                 }
  390.                 MAKE_VALUE(c[i].value);
  391.             }
  392.         }
  393.     } else if (HALF_CONNECTED) {
  394.         MAKE_LABEL(get_message("connectionPending"), 4);
  395.         MAKE_VALUE(current_host);
  396.     } else
  397.         MAKE_LABEL(get_message("notConnected"), 4);
  398.  
  399.     /* Add "OK" button at the lower left */
  400.  
  401.     w = XtVaCreateManagedWidget(
  402.         ObjConfirmButton, commandWidgetClass, about_form,
  403.         XtNfromVert, w,
  404.         XtNleft, XtChainLeft,
  405.         XtNbottom, XtChainBottom,
  406.         NULL);
  407.     XtAddCallback(w, XtNcallback, saw_about, 0);
  408.  
  409.     /* Pop it up */
  410.  
  411.     popup_popup(about_shell, XtGrabExclusive);
  412. }
  413.  
  414. #undef MAKE_LABEL
  415. #undef MAKE_VALUE
  416.  
  417. #endif /*]*/
  418.